//
//  DKRepayLoanContract.m
//  DanKU
//
//  Created by EDY on 2023/11/10.
//

#import "DKRepayLoanContract.h"
#import "DKWebViewController.h"

@interface DKRepayLoanContract()
@property(nonatomic,strong)UIView *dk_OrderRepayView;
@property(nonatomic,strong)UIButton *dk_repayRightBtn;

@end

@implementation DKRepayLoanContract


-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        self.backgroundColor =  DK_Hex(@"#FAFAFA");
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        [self creatUI];
    }
    return  self;
}

-(void)Contract{    
    DKWebViewController * dk_WebViewCtrl = [[DKWebViewController alloc] initWithUrl:DK_LoanAgreement withIsNavBar:YES];
    [self.viewController.navigationController pushViewController:dk_WebViewCtrl animated:YES];
}

-(void)creatUI{
    [self.contentView addSubview:self.dk_OrderRepayView];
    [self.dk_OrderRepayView addSubview:self.dk_repayRightBtn];
    
    [self.dk_OrderRepayView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self).offset(15);
        make.right.equalTo(self).offset(-15);
        make.top.bottom.equalTo(self.contentView);
    }];
    
    [self.dk_repayRightBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.dk_OrderRepayView).offset(-15);
        make.width.mas_equalTo(DK_SCREEN_W/2);
        make.top.bottom.equalTo(self.dk_OrderRepayView);
    }];
}

-(UIView*)dk_OrderRepayView{
    if (!_dk_OrderRepayView) {
        _dk_OrderRepayView = [[UIView alloc]init];
        _dk_OrderRepayView.backgroundColor = DK_Hex(@"#FFFFFF");
        _dk_OrderRepayView.layer.cornerRadius = 10;
    }
    return _dk_OrderRepayView;
}


- (UIButton *)dk_repayRightBtn {
    if (!_dk_repayRightBtn) {
        _dk_repayRightBtn = [[UIButton alloc] init];
        [_dk_repayRightBtn setTitle:@"View Loan Contract >" forState:UIControlStateNormal];
        [_dk_repayRightBtn setTitleColor:DK_Hex(@"#0F57F4") forState:UIControlStateNormal];
        _dk_repayRightBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentRight;
        _dk_repayRightBtn.titleLabel.font = [UIFont boldSystemFontOfSize:14];
        [_dk_repayRightBtn addTarget:self action:@selector(Contract) forControlEvents:UIControlEventTouchUpInside];
    }
    return _dk_repayRightBtn;
}


//获取View所在的Viewcontroller方法
- (UIViewController *)viewController {
    for (UIView* next = [self superview]; next; next = next.superview) {
        UIResponder *nextResponder = [next nextResponder];
        if ([nextResponder isKindOfClass:[UIViewController class]]) {
            return (UIViewController *)nextResponder;
        }
    }
    return nil;
}


@end
